Skip to content

chore(sidenav): update output names per #6677 - #7161

Closed
amcdnl wants to merge 6 commits into
angular:masterfrom
amcdnl:sidenav-outputs-6677
Closed

amcdnl wants to merge 6 commits into
angular:masterfrom
amcdnl:sidenav-outputs-6677

Conversation

@amcdnl

@amcdnl amcdnl commented Sep 19, 2017

Copy link
Copy Markdown
Contributor

Updates APIs per #6677

  • open | onOpen to openChange
  • close | onClose to closeChange

@jelbourn - onPositionChanged is a member declared with positionChanged output name. We might consider changing that member name to match the output name in this as well.

@amcdnl amcdnl self-assigned this Sep 19, 2017
@amcdnl
amcdnl requested a review from jelbourn September 19, 2017 01:30
@amcdnl
amcdnl requested a review from mmalerba as a code owner September 19, 2017 01:30
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 19, 2017
@jelbourn jelbourn changed the title chore(api): update apis per #6677 chore(sidenav): update output names per #6677 Sep 19, 2017
@jelbourn

jelbourn commented Sep 19, 2017 •

Copy link
Copy Markdown
Contributor

We should just eliminate closeChange and have openChange include the state.

We should remove on from all of the property names as well.

(with the old one still deprecated)

Comment thread src/lib/sidenav/drawer.ts Outdated

/** Event emitted when the drawer is fully opened. */
@Output('open') onOpen = new EventEmitter<MdDrawerToggleResult | void>();
@Output() openChange = new EventEmitter<MdDrawerToggleResult | void>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is really confusing now. I would expect openChange to fire when the drawer closes, since that is a change in the open state of the drawer. If we're going with this naming style we should get rid of the closeChange one and just emit booleans on the openChange stream whenever the drawer opens or closes.

We should also make it match the input (either both open or both opened) so that people can do 2-way binding

@jelbourn jelbourn added the P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful label Sep 22, 2017
@amcdnl

amcdnl commented Sep 24, 2017

Copy link
Copy Markdown
Contributor Author

@jelbourn - I've removed closeChange and updated usages to openChange. openChange already emitted a type which defined if it was closed or opened. This would feel more natural to me if it were a boolean, what do you guys think?

@mmalerba - The input for open is opened, so openChange wouldn't match the pattern {input}Change to do the 2-way binding without overriding it (which its already doing) or changing openChange to openedChange.

@mmalerba

Copy link
Copy Markdown
Contributor

+1 for changing emitted type to boolean.

I think the @Input was called opened in order to not conflict with the open() method. We could do something like this:

@Input('open') isOpen = false;
@Output() openChange = new EventEmitter<boolean>();
open() { ... }

or

@Input() opened = false;
@Output() openedChange = new EventEmitter<boolean>();
open() { ... }

I'm fine with either

@jelbourn

Copy link
Copy Markdown
Contributor

I generally prefer emitting event objects instead of primitives because we can always add more information to them later without it being a breaking change. So it would emit something like
MdSidenavOpenChangeEvent

I'd rather avoid doing isOpen since it would be inconsistent with the rest of the boolean properties around the library (and that inconsistency s what we're addressing in the first place).

@mmalerba

Copy link
Copy Markdown
Contributor

@jelbourn Agreed about isOpen being inconsistent. That's why in my example I renamed it to open using the string argument that @Input() can take. (I couldn't directly call it open because it would conflict with the open() method).

I also agree about emitting events in most cases, but not when there's a corresponding @Input(). Having both opened and openedChange gives the impression that you can do [(opened)]="isOpen", but this wouldn't work right if openedChange emitted objects instead of booleans.

@mmalerba

Copy link
Copy Markdown
Contributor

@jelbourn and I talked offline and agreed on the following:

@Input() opened: boolean;

@Output() openedChange: EventEmitter<boolean>;

@Output('opened') get _openedStream(): EventEmitter<void> { return filter(this.openedChange, o => o); }

@Output('closed') get _closedStream(): EventEmitter<void> { return filter(this.openedChange, o => !o); }

open() {...}

@amcdnl

amcdnl commented Sep 30, 2017

Copy link
Copy Markdown
Contributor Author

Given all the changes, I'm closing this and starting fresh w/ #7450

@amcdnl amcdnl closed this Sep 30, 2017
@amcdnl
amcdnl deleted the sidenav-outputs-6677 branch September 30, 2017 20:41
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes PR author has agreed to Google's Contributor License Agreement P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants